<?php
allowCors();
if (!methodsRequired(['post'])) return;
if (!checkAdmin($msg)) return;

if(isset($_REQUEST['dept_name'])){
    $dept = new Department($_REQUEST['dept_name']);

    if (isset($_REQUEST['dept_info']))
    $dept->setDeptInfo($_REQUEST['dept_info']);
    if(isset($_REQUEST['dept_manage_id']))
        $dept->setDeptManagerId($_REQUEST['dept_manage_id']);
    if ($db->add($dept)) {
        $msg->setCode(0);
    } else {
        $msg->setCode(1);
    }
}else{
    $msg->setCode(1);
}
echo $msg;